package com.sky.controller.admin;


import com.sky.dto.TUserDTO;
import com.sky.dto.UserPageQueryDTO;
import com.sky.entity.Employee;
import com.sky.entity.TUser;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.TUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController("AdminUserController")
@RequestMapping("/admin/user")
@Slf4j
@Api(tags = "用户管理接口")
public class UserController {

   @Autowired
   private TUserService tUserService;

   /**
    * 分页查询用户
    * @param userPageQueryDTO
    * @return
    */
   @GetMapping("/page")
   @ApiOperation("分页查询员工")
   public Result<PageResult> page(UserPageQueryDTO userPageQueryDTO) {
      log.info("分页查询员工{}", userPageQueryDTO);
      PageResult pageResult=tUserService.pageQuery(userPageQueryDTO);
      return  Result.success(pageResult);
   }

   /**
    * 根据id查询用户信息
    * @param id
    * @return
    */
   @GetMapping("/{id}")
   @ApiOperation("根据id查询用户信息")
   public Result<TUser> getUserById(@PathVariable Long id) {
      TUser tUser=tUserService.getUserById(id);
      return Result.success(tUser);
   }

   /**
    * 更新用户信息
    * @param tUserDTO
    * @return
    */
   @PutMapping
   @ApiOperation("更新用户信息")
   public Result<TUser> updateUser(@RequestBody TUserDTO tUserDTO) {
      log.info("编辑用户:{}", tUserDTO);
      tUserService.updateUser(tUserDTO);
      return Result.success();
   }
}
